{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.565151Z",
     "start_time": "2019-10-26T13:57:30.474135Z"
    }
   },
   "outputs": [],
   "source": [
    "import cv2\n",
    "import time, timeit\n",
    "from timeit import default_timer as timer\n",
    "import cProfile"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "# Profile Usage\n",
    "p = cProfile()\n",
    "p.runcall(vsm, tags[0], tags[1])\n",
    "p.print_stats()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.677219Z",
     "start_time": "2019-10-26T13:57:30.566451Z"
    }
   },
   "outputs": [],
   "source": [
    "from matplotlib.pyplot import imshow\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.680482Z",
     "start_time": "2019-10-26T13:57:30.678413Z"
    }
   },
   "outputs": [],
   "source": [
    "IMG = './292.bmp'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.684556Z",
     "start_time": "2019-10-26T13:57:30.681641Z"
    }
   },
   "outputs": [],
   "source": [
    "img = cv2.imread(IMG)\n",
    "#print('Image Dimensions :', img.shape)\n",
    "#imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.688498Z",
     "start_time": "2019-10-26T13:57:30.685646Z"
    }
   },
   "outputs": [],
   "source": [
    "g_img = cv2.imread(IMG, cv2.IMREAD_GRAYSCALE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.692075Z",
     "start_time": "2019-10-26T13:57:30.689968Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Image Dimensions : (640, 480)\n"
     ]
    }
   ],
   "source": [
    "print('Image Dimensions :', g_img.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.696184Z",
     "start_time": "2019-10-26T13:57:30.693020Z"
    }
   },
   "outputs": [],
   "source": [
    "#imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.700456Z",
     "start_time": "2019-10-26T13:57:30.697579Z"
    }
   },
   "outputs": [],
   "source": [
    "#cProfile.run(\"for i in range(1000) : cv2.morphologyEx(g_img, cv2.MORPH_OPEN, (5,5))\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.703593Z",
     "start_time": "2019-10-26T13:57:30.701348Z"
    }
   },
   "outputs": [],
   "source": [
    "#imshow(m_img, cmap='gray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.707699Z",
     "start_time": "2019-10-26T13:57:30.704468Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time Used 0.00023682100072619505 second\n"
     ]
    }
   ],
   "source": [
    "t1 = timer()\n",
    "ttt = cv2.morphologyEx(g_img, cv2.MORPH_OPEN, (5,5))\n",
    "t2 = timer()\n",
    "print(\"Time Used\", t2 - t1, \"second\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.712321Z",
     "start_time": "2019-10-26T13:57:30.708584Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time Used 0.0002925395965576172 second\n"
     ]
    }
   ],
   "source": [
    "t1 = time.time()\n",
    "ttt = cv2.morphologyEx(g_img, cv2.MORPH_OPEN, (5,5))\n",
    "t2 = time.time()\n",
    "print(\"Time Used\", t2 - t1, \"second\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-26T13:57:30.716258Z",
     "start_time": "2019-10-26T13:57:30.713301Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time Used 0.0007050049999999253 second\n"
     ]
    }
   ],
   "source": [
    "t1 = time.process_time()\n",
    "ttt = cv2.morphologyEx(g_img, cv2.MORPH_OPEN, (5,5))\n",
    "t2 = time.process_time()\n",
    "print(\"Time Used\", t2 - t1, \"second\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
